<?php

namespace app\api\controller;

use app\common\controller\Api;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['banner','hotMachine','currencyNews'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     */
    public function index()
    {

        $this->success('请求成功');
    }

    /**
     * banner图(C B)
     */
    public function banner()
    {

        if($this->auth->getUserinfo()['merchant_state']==1){
            $admin_id = $this->auth->getUserinfo()['id'];
        }else{
            $admin_id = 1;
        }
        $bannerRe=\app\admin\model\Banner::get(['admin_id' =>  $admin_id]);

        $this->success(__('获取成功'), $bannerRe);
    }

    /**
     * 首页订单(B)
     */
    public function latestOrder()
    {
        $admin_id = $this->auth->getUserinfo()['id'];

        $latestOrderRe=\app\admin\model\Order::with('user,goods')
            ->where('admin_id',$admin_id)
            ->order('createtime desc')
            ->limit(5)
            ->select();

        $this->success(__('获取成功'), $latestOrderRe);
    }

    /**
     * 首页 主流币种/创新区(C)
     */
    public function coinNews()
    {
		$seltype = $this->request->post("seltype");
		
        $this->success(__('预留主流币种/创新区未获取'));
    }
	
	/**
	 * 首页 热门矿机(C)
	 */
	public function hotMachine()
	{
		// $re=\app\admin\model\Goods::orderRaw('rand()')->limit(5)->select(); 
		// $this->success(('获取成功'),$re);
		$this->success(('预留此处热门矿机与商品表信息不对照'));
	}

    /*
     * 区块链币种信息
     */
    public function currencyNews()
    {
        $data = [
            'main_stream' => [],
            'innovate' => [],
        ];

        $data['main_stream'] = [
            [
                'currency' => 'Bitcoin',
                'algorithm' => 'SHAX',
                'calc_power' => '26.33',
                'calc_power_unit' => 'EH/s',
                'curr_price' => '￥ 264.1',
                'theo_bene' => '￥ 264.1',
                'theo_bene_unit' => '/T',
                'curr_value' => '2242 BTC/T'
            ],
            [
                'currency' => 'Ethereum',
                'algorithm' => 'SHAX',
                'calc_power' => '26.33',
                'calc_power_unit' => 'EH/s',
                'curr_price' => '￥ 264.1',
                'theo_bene' => '￥ 264.1',
                'theo_bene_unit' => '/T',
                'curr_value' => '2242 BTC/T'
            ],
            [
                'currency' => 'Polkadot',
                'algorithm' => 'SHAX',
                'calc_power' => '26.33',
                'calc_power_unit' => 'EH/s',
                'curr_price' => '￥ 264.1',
                'theo_bene' => '￥ 264.1',
                'theo_bene_unit' => '/T',
                'curr_value' => '2242 BTC/T'
            ],
            [
                'currency' => 'DOGE',
                'algorithm' => 'SHAX',
                'calc_power' => '26.33',
                'calc_power_unit' => 'EH/s',
                'curr_price' => '￥ 264.1',
                'theo_bene' => '￥ 264.1',
                'theo_bene_unit' => '/T',
                'curr_value' => '2242 BTC/T'
            ],
            [
                'currency' => 'HNT',
                'algorithm' => 'SHAX',
                'calc_power' => '26.33',
                'calc_power_unit' => 'EH/s',
                'curr_price' => '￥ 264.1',
                'theo_bene' => '￥ 264.1',
                'theo_bene_unit' => '/T',
                'curr_value' => '2242 BTC/T'
            ],
        ];
        $this->success(__('获取成功'), $data);
    }
}
